package com.tms.app.tms.utils;

import com.amap.api.fence.GeoFenceClient;
import com.amap.api.fence.GeoFenceListener;
import com.amap.api.location.DPoint;
import com.tms.app.tms.app.MyApp;

import static com.amap.api.fence.GeoFenceClient.GEOFENCE_IN;
import static com.amap.api.fence.GeoFenceClient.GEOFENCE_OUT;
import static com.amap.api.fence.GeoFenceClient.GEOFENCE_STAYED;
// GEOFENCE_IN;//进入地理围栏
// GEOFENCE_OUT;// 退出地理围栏
// GEOFENCE_STAYED;// 停留在地理围栏内10分钟
/**
 * Created by Administrator on 2018/1/13 0013.
 */

public class GeoFenceUtil {

    private  static GeoFenceClient mGeoFenceClient=null;
    //定义接收广播的action字符串
    public static final String GEOFENCE_BROADCAST_ACTION = "com.location.apis.geofencedemo.broadcast";

    public static GeoFenceClient getInstance(GeoFenceListener fenceListenter) {
        if (mGeoFenceClient!=null){
            mGeoFenceClient.setGeoFenceListener(fenceListenter);
            return mGeoFenceClient;
        }

        //实例化地理围栏客户端
        GeoFenceClient mGeoFenceClient = new GeoFenceClient(MyApp.getInstance().getApplicationContext());
        //设置希望侦测的围栏触发行为，默认只侦测用户进入围栏的行为
       // mGeoFenceClient.setActivateAction(GEOFENCE_IN|GEOFENCE_OUT|GEOFENCE_STAYED);
        mGeoFenceClient.setActivateAction(GEOFENCE_IN|GEOFENCE_OUT);
        mGeoFenceClient.setGeoFenceListener(fenceListenter);
        //创建并设置PendingIntent
        mGeoFenceClient.createPendingIntent(GEOFENCE_BROADCAST_ACTION);
        return mGeoFenceClient;
    }


    /*******
     *
     * @param client
     * @param dPoint
     * @param customId   自有ID
     *                   最大创建的围栏数目，最大值为25，默认为10
     */
    public static void addGeoFence(GeoFenceClient client, DPoint dPoint,String customId ){
        //创建一个中心点坐标
        DPoint centerPoint = new DPoint();
        //设置中心点纬度
        centerPoint.setLatitude(39.123D);
        //设置中心点经度
        centerPoint.setLongitude(116.123D);
        //执行添加围栏的操作
       // client.addGeoFence("肯德基","餐饮",centerPoint,1000F,10,customId);
        client.addGeoFence(dPoint,1000F,customId);

    }

    public static void removeGeoFence(GeoFenceClient client ){
        //会清除所有围栏
        client.removeGeoFence();

    }




}
